package com.aurora.CETManagementSystem;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class codeAutoGenerate {

    public static void main(String[] args) {
        //构建一个代码生成器 对象
        AutoGenerator autoGenerator = new AutoGenerator();


        //配置策略
        //设置模板引擎

        //1.全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        //获取系统当前目录
        String projectPath = System.getProperty("user.dir");
        //设置代码输出路径
        globalConfig.setOutputDir(projectPath+"/src/main/java");
        //设置作者
        globalConfig.setAuthor("aurora");
        //生成完毕后是否打开文件资源管理器
        globalConfig.setOpen(true);
        //是否覆盖原文件
        globalConfig.setFileOverride(false);
        //去掉Service的I前缀
        //globalConfig.setServiceName("%sService");

        //设置全局配置
        autoGenerator.setGlobalConfig(globalConfig);

        //设置数据源
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/cetmanagementsystem?useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai");
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("root");
        dataSourceConfig.setDbType(DbType.MYSQL);
        autoGenerator.setDataSource(dataSourceConfig);

        //包的配置
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setModuleName("CETManagementSystem");//设置模块名
        packageConfig.setParent("com.aurora");//设置父类包名
        packageConfig.setEntity("pojo");//设置实体类包名
        packageConfig.setMapper("mapper");
        //packageConfig.setService("service");
        //packageConfig.setController("controller");

        autoGenerator.setPackageInfo(packageConfig);//包配置丢进去


        // 策略配置
        StrategyConfig strategy = new StrategyConfig();

        strategy.setInclude("news","testlog","user_info","account");//设置要映射的表名称

        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);    //是否使用Lombok
        //strategy.setLogicDeleteFieldName("deleted"); //设置逻辑删除字段名


        strategy.setRestControllerStyle(true);//开启Restful风格驼峰命名格式
        strategy.setControllerMappingHyphenStyle(true); // localhost:8080/hello_id_2

        autoGenerator.setStrategy(strategy); //策略配置完毕

        autoGenerator.execute();//执行

    }

}



